<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>CodeFlask Test Page</title>
  <style>
    body {
      font-family: Arial;
      margin: 30px;
    }

    .test {
      background: #eee;
    }
  </style>
</head>
<body>
  
   <div class="convertImage">
        <div class="title">
            Json 工具
        </div>
        <div class="content">
            <div id="editor" style="width:500px;height:400px">
			/**
 * Payload Decoder for Chirpstack and Milesight network server
 * 
 * Copyright 2021 Milesight IoT
 * 
 * @product EM500-PT100
 */
function Decode(fPort, bytes) {
    var decoded = {};

    for (var i = 0; i < bytes.length;) {
        var channel_id = bytes[i++];
        var channel_type = bytes[i++];
        // BATTERY
        if (channel_id === 0x01 && channel_type === 0x75) {
            decoded.battery = bytes[i];
            i += 1;
        }
        // TEMPERATURE
        else if (channel_id === 0x03 && channel_type === 0x67) {
            // ℃
            decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;
            i += 2;

            // ℉
            // decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10 * 1.8 + 32;
            // i +=2;
        } else {
            break;
        }
    }

    return decoded;
}

/* ******************************************
 * bytes to number
 ********************************************/
function readUInt16LE(bytes) {
    var value = (bytes[1] << 8) + bytes[0];
    return value & 0xffff;
}

function readInt16LE(bytes) {
    var ref = readUInt16LE(bytes);
    return ref > 0x7fff ? ref - 0x10000 : ref;
}
			</div>
            <div class="btn-group button" role="group" >
                <button type="button" class="btn btn-default" @click="jsonFormat">Json 格式化（format)</button>
                <button type="button" class="btn btn-default" onclick="getData()">Json 压缩</button>
            </div>
        </div>
    </div>
	
	
  <script src="./ace.min.js"></script>
<script src="./ext-beautify.min.js"></script>
<script src="./ext-language_tools.min.js"></script>
<script src="./mode-javascript.min.js"></script>
<script src="./theme-xcode.min.js"></script>

<script>
 var editor = ace.edit('editor');// 这个地方就是id是editor的div
                    editor.setTheme('ace/theme/xcode');
                    let jsMode = ace.require('ace/mode/javascript').Mode;
                    editor.session.setMode(new jsMode());

function getData()
{
var editor=ace.edit('editor');
console.log(editor.getValue());
}

</script>
</body>
</html>
